/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.vienthonga.product.logic;

import com.vienthonga.hibernate.dao.ShowProductDAO;
import com.vienthonga.hibernate.pojo.TProduct;
import java.util.List;

/**
 *
 * @author DoanHa
 */
public class ShowMobilephoneByManyfacturerLogic {

    public List<TProduct> getMobilephoneByManufacturer(String manufacturerID, int pageIndex) {
        //tinh chi so bat dau
        int itemsOnPage = GetItemsOnPage();
        int start = (pageIndex - 1) * itemsOnPage;
        ShowProductDAO showProductDao = new ShowProductDAO();
        return showProductDao.getMobilePhoneByManufacturer(manufacturerID, start, itemsOnPage);
    }

    public int GetItemsOnPage() {
        return ShowProductDAO.GetItemsOnPage();
    }

    public int caculatePaging(String manufacturerID) {
        int totalItem = ShowProductDAO.GetItemsTotal(manufacturerID);
        int itemOnPage = GetItemsOnPage();
        int numberOfPage;
        if (totalItem % itemOnPage == 0) {
            numberOfPage = totalItem / itemOnPage;
        } else {
            numberOfPage = totalItem / itemOnPage + 1;
        }
        return numberOfPage;
    }

 
}
